package arsmodeller.commands;

import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.commands.Command;

import arsmodeller.model.BusinessProcess;
import arsmodeller.model.MainModel;

public class BusinessProcessCreateCommand extends Command {
	private MainModel en;
	private BusinessProcess bp;

	public BusinessProcessCreateCommand() {
		super();
		bp = null;
		en = null;
	}

	public void setBusinessProcess(Object e) {
		if (e instanceof BusinessProcess) {
			this.bp = (BusinessProcess) e;
		}
	}

	public void setEnterprise(Object en) {
		if (en instanceof MainModel)
			this.en = (MainModel) en;
	}

	public void setLayout(Rectangle lay) {
		if (bp == null)
			return;
		bp.setLayout(lay);
	}

	@Override
	public boolean canExecute() {
		if (bp == null || en == null)
			return false;
		return true;
	}

	@Override
	public void execute() {
		en.addChild(bp);
	}

	@Override
	public void undo() {
		en.removeChild(bp);
	}

	@Override
	public boolean canUndo() {
		if (en == null || bp == null) {
			return false;
		}
		return en.contains(bp);
	}

}
